import config as cfg
import pdb


#------------------------------------------------------------------
#            IB Config definitions
#------------------------------------------------------------------
""" used by IBinterface 2 decide which messages to handle"""
ibwrappers = {'basic':['tickPrice'],
             'noisy':['tickPrice','tickSize']}

debug = True

# IB TickType
enumtoname = {
1 : 'bid' , 2 : 'ask', 4 : 'last', 
6 : 'high', 7 : 'low', 9 : 'close'
}

#------------------------------------------------------------------
#            EWRapper Handlers
#------------------------------------------------------------------
gcount = 0

## class PriceMsg():
##     def __init__(self, tickerid, price, field):
##         self.price = price
##         self.field = field
##         self.tickerId = tickerid
        
##     def __str__(self):
##        return '%s %.2f' % (ticktypemap[self.field], self.price)

def tickPrice(self, tickerId, field, price, canAutoExecute):
    t = (('event','tickPrice'),('tickerId',tickerId),
         ('field', enumtoname[field]),('price',price))
    
    #ibmsg = PriceMsg(tickerId,price,field)
    cfg.msgq.put(t)
    

scannerData = lambda s:s

#------------------------------------------------------------------
# list of handlers to pass to the EWrapper class factory. grouped
# my mode: basic, noisy, scannining, account         
#------------------------------------------------------------------

sessionmode = {'basic':{'tickPrice':tickPrice, },
               'noisy':{'tickPrice':tickPrice,'scannerData':scannerData, }
               }






